package com.guoyh.procommon.activity

import android.content.Context
import android.os.Bundle
import androidx.core.os.bundleOf
import com.guoyh.baseutils.aroute.Pager
import com.guoyh.baseutils.ext.getFragmentForPath
import com.guoyh.baseutils.mylog.Loger
import com.guoyh.baseutils.utils.ActStartUtils
import com.guoyh.baseutils.viewModel.SupportViewModel
import com.guoyh.bilbase.ext.getIntentStr
import com.guoyh.mcommon.R
import com.guoyh.mcommon.databinding.MNavigationActivityBinding
import com.guoyh.procommon.base.XBaseActivity

class CommonNavigationActivity :
    XBaseActivity<SupportViewModel, MNavigationActivityBinding>() {

    override val layoutId: Int = R.layout.m_navigation_activity


    override fun viewModelClass() = SupportViewModel::class.java


    companion object {
        // 路径
        const val CommonNavi_Path = "CommonNavi_Path"
        // 描述`
        const val CommonNavi_Decs = "CommonNavi_Desc"
        fun start(cont: Context, pager: Pager) {
            ActStartUtils.startActivity(
                cont, CommonNavigationActivity::class.java, bundleOf(
                    CommonNavi_Path to pager.path,
                    CommonNavi_Decs to pager.decs
                )
            )
        }
    }

    val path by lazy {
        getIntentStr(CommonNavi_Path)
    }

    val decs by lazy {
        getIntentStr(CommonNavi_Decs)
    }

    override fun initView(savedInstanceState: Bundle?) {
      try {
          //开启事务
          val beginTransaction = supportFragmentManager.beginTransaction()
          beginTransaction.replace(mDataBind.commonNavigationFrame.id, getFragmentForPath(path))
          //最后一步 记得commit
          beginTransaction.commit()
      }catch (e:Exception){
          Loger.ee(e.message)
          finish()
      }
    }


}